﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Sales;

namespace NotebookS2.Sales.Logs
{
    public partial class LOGS_SalesOrder : Form
    {
        public LOGS_SalesOrder()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public void PrintPreview()
        {
            if (xtraTabLogs.SelectedTabPageIndex == 0)
            {
                gridControl1.ShowPrintPreview();
            }
            else
            {
                gridControlPerItem.ShowPrintPreview();
            }
        }

        void BindGrid()
        {
            OrderManager oManager = new OrderManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
                dt = oManager.GetSalesOrder(Convert.ToDateTime(dtFROM.EditValue), Convert.ToDateTime(dtTO.EditValue), chkDraft.Checked, chkPosted.Checked, true, chkOpen.Checked, chkClosed.Checked);
            
            gridControl1.DataSource = dt;
            gridControl1.Refresh();

            oManager.Close();
        }


        void BindGridPerItem()
        {
            OrderManager oManager = new OrderManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            dt = oManager.GetSalesOrderPerItem(Convert.ToDateTime(dtFromItem.EditValue), Convert.ToDateTime(dtToItem.EditValue), 
                chkDraftPerItem.Checked, chkPostedPerItem.Checked, true, chkOpenPerItem.Checked, chkClosedPerItem.Checked);
            
            gridControlPerItem.DataSource = dt;
            gridControlPerItem.Refresh();

            oManager.Close();
        }
        private void btnPreview_Click(object sender, EventArgs e)
        {
           // DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(LF200));
            BindGrid();
            //DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void LOGS_SalesOrder_Load(object sender, EventArgs e)
        {
            dtFROM.EditValue = System.DateTime.Now.ToShortDateString();
            dtTO.EditValue = System.DateTime.Now.ToShortDateString();

            dtFromItem.EditValue = System.DateTime.Now.ToShortDateString();
            dtToItem.EditValue = System.DateTime.Now.ToShortDateString();
        }

        private void btnRequeryItems_Click(object sender, EventArgs e)
        {
            //DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(LF200));
            BindGridPerItem();
            //DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }
    }
}
